#include <stdio.h>
#define max(a,b) ((a)>(b))?(a):(b)
#define MAXPEO 10000
#define MINTIME 0

int list[MAXPEO];

int CrossTime (int * list, int num);

int main (void)
{
    list[0] = 1;
    list[1] = 2;
    list[2] = 2;
    list[3] = 10;
    printf("CrossTime: %d\n",CrossTime(list,4));
}

int CrossTime (int * list, int num)
{
    void swap (int i, int j, int * list);
    int MaxPass (int * list, int sum);

    int CurTime1 = 0, Tn, Tn_1, T2, T1, CurTime2 = 0;
    if(num==2)
        return max(list[0],list[1]);
    if(num==1)
        return list[0];
    
    Tn = MaxPass(list,num);
    Tn_1 = MaxPass(list,num-1);
    T1 = list[0];
    T2 = list[1];
    CurTime1 = CrossTime(list,num-1) + Tn + T1;
    CurTime2 = CrossTime(list,num-2) + T2 + T1 + Tn + T2;
    int k = (CurTime1 < CurTime2)? CurTime1: CurTime2;
    return k;
}

int MaxPass (int *list, int num)
{
    int Max = MINTIME;
    for(int i = 0;i < num;i++)
        if(list[i] > Max)
            Max = list[i];
    return Max;
}
